package com.ywk.pattern._24_chain;

public abstract class Manager {
    protected String name;
    protected Manager superior;

    public Manager(String name) {
        this.name = name;
    }

    public void setSuperior(Manager superior) {
        this.superior = superior;
    }

    public abstract void requestApplication(Request request);
}

class CommonManager extends Manager {

    public CommonManager(String name) {
        super(name);
    }

    @Override
    public void requestApplication(Request request) {
        if (request.getRequestType().equals("���") && request.getNumber() <= 2) {
            System.out.println("������׼�� " + request.toString());
        } else {
            if (superior != null) {
                superior.requestApplication(request);
            }
        }
    }
}

class Majordomo extends Manager {

    public Majordomo(String name) {
        super(name);
    }

    @Override
    public void requestApplication(Request request) {
        if (request.getRequestType().equals("���") && request.getNumber() <= 5) {
            System.out.println("�ܼ���׼�� " + request.toString());
        } else {
            if (superior != null) {
                superior.requestApplication(request);
            }
        }
    }
}

class GeneralManager extends Manager {

    public GeneralManager(String name) {
        super(name);
    }

    @Override
    public void requestApplication(Request request) {
        if (request.getRequestType().equals("���")) {
            System.out.println("�ܾ�����׼�� " + request.toString());
        } else {
            if (request.getRequestType().equals("��н") && request.getNumber() <= 500) {
                System.out.println("�ܾ�����׼�� " + request.toString());
            } else {
                System.out.println("�ܾ�����˵��");
            }
        }
    }
}

class Mai {
    public static void main(String[] args) {
        CommonManager commonManager = new CommonManager("����");
        Majordomo majordomo = new Majordomo("�ڼ�");
        GeneralManager generalManager = new GeneralManager("�ܼ���");
        commonManager.setSuperior(majordomo);
        majordomo.setSuperior(generalManager);
        Request request = new Request();
        request.setRequestType("��н");
        request.setNumber(400);
        request.setRequestContent("С���н");

        commonManager.requestApplication(request);

        request.setRequestType("��н");
        request.setNumber(700);
        request.setRequestContent("С���н");

        commonManager.requestApplication(request);


        request.setRequestType("���");
        request.setNumber(2);
        request.setRequestContent("С�����");

        commonManager.requestApplication(request);


        request.setRequestType("���");
        request.setNumber(5);
        request.setRequestContent("С����� ");

        commonManager.requestApplication(request);

    }
}

class Request {
    private String requestType;
    private String requestContent;
    private int number;

    public String getRequestType() {
        return requestType;
    }

    public void setRequestType(String requestType) {
        this.requestType = requestType;
    }

    public String getRequestContent() {
        return requestContent;
    }

    public void setRequestContent(String requestContent) {
        this.requestContent = requestContent;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return "Request{" +
                "requestType='" + requestType + '\'' +
                ", requestContent='" + requestContent + '\'' +
                ", number=" + number +
                '}';
    }
}
